/*
 * Matrix_Nodelist_GB2312.h
 *
 * Created by GF on 2023/3/10.
 */

#ifndef MATRIX_NODELIST_GB2312_H
#define MATRIX_NODELIST_GB2312_H

/* Vector NodeList 节点 (Node) 结构 */
struct Vector_Node {

    int Index;     /* Vector 的索引 */
    double Value;  /* Vector 的数据 */
    char Type[8];  /* Vector 的类型, 如 Row 向量, Column 向量, Anonymous 向量等 */
    /* ********************************************** */
    struct Vector_Node* Prev; /* Vector Node 的前一节点 */
    struct Vector_Node* Next; /* Vector Node 的下一节点 */
};

/* Matrix NodeList 节点 (Node) 结构 */
struct Matrix_Node {

    int RowIdx;   /* Matrix 的行索引 */
    int ColIdx;   /* Matrix 的列索引 */
    double Value; /* Matrix 的数据 */
    /* ********************************************** */
    struct Matrix_Node* Prev; /* Matrix Node 的前一节点 */
    struct Matrix_Node* Next; /* Matrix Node 的下一节点 */
};

/* Vector NodeList 向量初始化 */
struct Vector_Node* Vector_NodeList_Init(char* Vector_Type);

/* Vector NodeList 向量最大长度 */
int Vector_NodeList_Max_Length(struct Vector_Node* Vector_Head);

/* Vector NodeList 向量末尾添加元素 */
void Vector_NodeList_Append(struct Vector_Node* Vector_Head, double Value);

/* Vector NodeList 向量通过索引查找元素 */
double Vector_NodeList_Find_Element_by_Index(struct Vector_Node* Vector_Head, int Index);

/* Vector NodeList 向量格式化输出 */
void Vector_NodeList_Format_Print(struct Vector_Node* Vector_Head);

/* Vector NodeList 向量元素的和 */
double Vector_NodeList_Sum_of_Elements(struct Vector_Node* Vector_Head);

/* Vector NodeList 向量的点乘/点积(Dot Product) */
double Vector_NodeList_Dot_Product(struct Vector_Node* Vector_A, struct Vector_Node* Vector_B);

/* Matrix NodeList 初始化 */
struct Matrix_Node* Matrix_NodeList_Init();

/* Matrix NodeList 最大行数 */
int Matrix_NodeList_Max_Rows_Num(struct Matrix_Node* Matrix_Head);

/* Matrix NodeList 最大列数 */
int Matrix_NodeList_Max_Cols_Num(struct Matrix_Node* Matrix_Head);

/* Matrix NodeList 按 Index 查找 Value */
double Matrix_NodeList_Find_Value_By_Index(struct Matrix_Node* Matrix_Head, int Row_Index, int Col_Index);

/* Matrix NodeList 格式化输出 */
void Matrix_NodeList_Format_Print(struct Matrix_Node* Matrix_Head);

/* Matrix NodeList 末尾添加节点 */
void Matrix_NodeList_Append(struct Matrix_Node* Matrix_Head, int Row_Index, int Col_Index, double Value);

/* Matrix NodeList 矩阵链表完整复制 */
struct Matrix_Node* Matrix_NodeList_Full_Copy(struct Matrix_Node* Matrix_Head_Source);

/* Matrix NodeList 按 Sequence 删除行 */
void Matrix_NodeList_Delete_Row_By_Sequence(struct Matrix_Node* Matrix_Head, int RowSeq, int Reindex);

/* Matrix NodeList 按 Sequence 删除列 */
void Matrix_NodeList_Delete_Col_By_Sequence(struct Matrix_Node* Matrix_Head, int ColSeq, int Reindex);

/* Matrix NodeList 清空所有节点 */
void Matrix_NodeList_Free(struct Matrix_Node* Matrix_Head);

/* 行列式(Determinant) NodeList 查找 元(元素) 的 余子式(Cofactor;) */
struct Matrix_Node* Determinant_NodeList_Find_Cofactor_of_Element(struct Matrix_Node* Det_Head, int EleRowIdx, int EleColIdx);

/* 行列式(Determinant) NodeList 求值 - 递归降阶法 */
double Determinant_NodeList_Result_By_Recurrence_Reduced_Order(struct Matrix_Node* Determinant_Head, int Order);

#endif //MATRIX_NODELIST_GB2312_H
